﻿using PLCDBTest.Dto;
using PLCTest.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PLCTest.BO
{
    public class PlanarZuPanPlcActionBO
    {
        ///// <summary>
        ///// 设备号
        ///// </summary>
        //public string EquipmentCode { get; set; }
        ///// <summary>
        ///// 任务号
        ///// </summary>
        //public int TaskCode { get; set; }
        ///// <summary>
        ///// 目标设备号
        ///// </summary>
        //public int ToEquipmentCode { get; set; }
        ///// <summary>
        ///// 托盘码
        ///// </summary>
        //public string PalletBarcode { get; set; }
        ///// <summary>
        ///// 握手类型
        ///// </summary>
        //public short ActionType { get; set; }
        ///// <summary>
        ///// 托盘类型
        ///// </summary>
        //public byte PalletType { get; set; }
        ///// <summary>
        ///// 报警代码
        ///// </summary>
        //public byte AlrmCode { get; set; }

        ///// <summary>
        ///// 单机任务标识
        ///// </summary>
        //public byte Reserve { get; set; }
        ///// <summary>
        ///// 预留2
        ///// </summary>
        //public byte Reserve2 { get; set; }
        ///// <summary>
        ///// 预留3
        ///// </summary>
        //public byte Reserve3 { get; set; }
        ///// <summary>
        ///// 预留4
        ///// </summary>
        //public byte Reserve4 { get; set; }

        ///// <summary>
        ///// 组盘数据创建申请
        ///// </summary>
        //public byte ZupanRequest { get; set; }

        ///// <summary>
        ///// 组盘数据申请响应
        ///// </summary>
        //public byte ZupanResponse { get; set; }

        ///// <summary>
        ///// 预留-0
        ///// </summary>
        //public byte Reserve_0 { get; set; }

        ///// <summary>
        ///// 预留-1
        ///// </summary>
        //public byte Reserve_1 { get; set; }

        ///// <summary>
        ///// 预留-2
        ///// </summary>
        //public byte Reserve_2 { get; set; }

        ///// <summary>
        ///// 预留-3
        ///// </summary>
        //public byte Reserve_3 { get; set; }

        #region 电池信息
        
        /// <summary>
        /// 电池集合
        /// </summary>
        public List<ZupanBatteryItemDto> BatteryItems { get; set; }

        #endregion


        public void Serialize(byte[] bytes)
        {


            //EquipmentCode = HelperByte.GetDIntAt(bytes, 0).ToString();
            //TaskCode = HelperByte.GetDIntAt(bytes, 4);
            //ToEquipmentCode = HelperByte.GetDIntAt(bytes, 8);
            //int length = HelperByte.GetSIntAt(bytes, 13);
            //PalletBarcode = HelperByte.GetCharsAt(bytes, 14, length);
            //ActionType = HelperByte.GetIntAt(bytes, 32);
            //PalletType = HelperByte.GetByteAt(bytes, 34);
            //AlrmCode = HelperByte.GetByteAt(bytes, 35);
            //Reserve = HelperByte.GetByteAt(bytes, 36);//单机任务标志
            //Reserve2 = HelperByte.GetByteAt(bytes, 37);
            //Reserve3 = HelperByte.GetByteAt(bytes, 38);
            //Reserve4 = HelperByte.GetByteAt(bytes, 39);

            //ZupanRequest = HelperByte.GetByteAt(bytes, 0);
            //ZupanResponse = HelperByte.GetByteAt(bytes, 1);
            //Reserve_0 = HelperByte.GetByteAt(bytes, 2);
            //Reserve_1 = HelperByte.GetByteAt(bytes, 3);
            //Reserve_2 = HelperByte.GetByteAt(bytes, 4);
            //Reserve_3 = HelperByte.GetByteAt(bytes, 5);

            //电池信息集合 TODO测试OK则使用此方案
            BatteryItems = new List<ZupanBatteryItemDto>();
            for (int i = 0; i < bytes.Length / 36; i++)
            {
                ZupanBatteryItemDto item = new ZupanBatteryItemDto();
                int lengthItem = HelperByte.GetSIntAt(bytes, 1 + 36 * i);
                item.BatteryCode = HelperByte.GetCharsAt(bytes, 2 + 36 * i, lengthItem).Trim();
                item.BatteryType = HelperByte.GetIntAt(bytes, 32 + 36 * i);
                item.BatteryGear = HelperByte.GetByteAt(bytes, 34 + 36 * i);
                BatteryItems.Add(item);
            }


        }
    }
}
